package cn.com.thingo.hyintelligent.util;

import cn.com.thingo.hyintelligent.model.http.api.EzApis;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class EzHttpUtils {
    private static EzHttpUtils mInstance;
    private static Retrofit retrofit;
    private static volatile EzApis ezApis = null;
private EzHttpUtils(){
    // 初始化okhttp
    OkHttpClient client = new OkHttpClient.Builder()
            .build();

    // 初始化Retrofit
    retrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl(EzApis.HOST)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

    public static EzHttpUtils getInstance() {
        if (mInstance == null) {
            synchronized (EzHttpUtils.class) {
                if (mInstance == null) {
                    mInstance = new EzHttpUtils();
                }
            }
        }
        return mInstance;
    }



    public  EzApis getEzApis() {
        if (ezApis == null) {
            synchronized (EzApis.class) {
                ezApis = retrofit.create(EzApis.class);
            }
        }
        return ezApis;
    }
}
